from mxnet import nd
from mxnet.gluon import nn
from mxnet import gluon


class CenteredLayer(nn.Block):
    def __init__(self, **kwargs):
        super(CenteredLayer, self).__init__(**kwargs)

    def forward(self, x):
        return x - x.mean()


layer = CenteredLayer()
print(layer(nd.array([1,2,3,4,5])))

net = nn.Sequential()
with net.name_scope():
    net.add(nn.Dense(128, activation='relu'))
    net.add(nn.Dense(10))
    net.add(CenteredLayer())

net.initialize()
y = net(nd.random.uniform(shape=(4,8)))
print(y.mean())

my_param = gluon.Parameter('test', shape=(3, 3))
my_param.initialize()
print(my_param.data(), my_param.grad())

pd = gluon.ParameterDict(prefix='block1_')
print(pd)
# fixme error
pd.get('test', shape=(3,3))
print(pd)
